/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package elemento;

import java.util.Map;

/**
 *
 * @author Jônatas
 */
public class Empresa implements SQLAble, Comparable<Empresa> {

    private int id;
    private String nome;

    public Empresa() {
    }

    public Empresa(int id, String nome) {
        this.id = id;
        this.nome = nome;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Empresa other = (Empresa) obj;
        if (this.id != other.id) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 31 * hash + this.id;
        return hash;
    }

    public String getSQLInsertString(String tableName) {
        String sql = "INSERT INTO " + tableName + " ('NOME') VALUES "
                + "("
                + "'" + seekForNull(this.nome) + "'"
                + ");";

        return sql;
    }

    public String getSQLUpdateString(String tableName, Map<String, Object> parametersMap) {
        String sql = "UPDATE " + tableName + " SET "
                + "'NOME' = '" + seekForNull(this.nome).replaceAll("'", "''") + "' ";
        sql += "WHERE " + tableName + ".'ID' = '" + this.id + "'";

        return sql;
    }

    public static String seekForNull(String s) {
        if (s == null) {
            return "";
        }
        return s;
    }

    public int compareTo(Empresa o) {
        return nome.compareTo(o.getNome());
    }
}
